<?php   
   //session_start();
    include_once("../classeBDD/connectBdd.php");
    /*include_once '../classeBDD/connectBdd.php';
    include_once"../commune/Entet.php";
    include_once"../commune/contenu.php";*/
    $sql = sql::connect();
    $donners= explode(';',$_GET['param']);
    for($i = 0; $i < sizeof($donners); ++$i){
          $table[strstr($donners[$i], '=', true)]=substr(strstr($donners[$i], '='),1);
    }
    
  
  if(isset ($_POST['ok'])&&isset($table)){
    $id_nom = md5(uniqid(rand(), true));
    $type=substr(strstr($table['type'], '/'),1);
    //$nom ="images_Annonces/".$id_nom.".".$type;
   // $nom ="../web/images_Annonces/123.png";
   /* $nom ="images_Annonces/12aaa3.png";
                         $resultat = move_uploaded_file($_SESSION['img_blob'], $nom);
                      if ($resultat){ echo "Transfert réussi";}
                      die;*/
    $nom="'".$table['nom_image']."'";
    $requery="INSERT INTO annonce(IdAnonce,type_annonce,nom,prenom,mail,telephone,ttitre_annonce,text_annonce,prix,vous_etes,categorie,region,images)";
   $requery .="VALUES('','".$table['type_annonce']."','".$table['nom']."','".$table['prenom']."','".$table['mail']."','";
   $requery .=$table['telephone']."','".$table['titreannonce']."','".$table['texteannonce']."','".$table['prix']."','".$table['vous_etes']."','".$table['categorie']."','".$table['region']."',".$nom.")";
   $requete = $sql->query($requery);
          
   /*$id_annonce= $sql->insert_id();
   $requery_Image .="INSERT INTO images(img_id,img_nom,img_taille,img_largeur,img_hauteur,img_type,img_blob,id_annonce)";
   $requery_Image .="VALUES('','".$table['nom_image']."','".$table['taill']."','".$table['largeur']."','".$table['hauteur']."','".$table['type']."','".$_SESSION['img_blob']."','".$id_annonce."')";
   $requery_Image = $sql->query($requery_Image);*/
   echo '<script language="Javascript">
                            document.location.replace("./index.php");
                            </script>';
  }
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-type" content="text/html; charset=utf-8" />
		<title>Jquery Inline Form Validation Engine</title>
		<link rel="stylesheet" href="/css/validationEngine.jquery.css" type="text/css" media="screen" title="no title" charset="utf-8" />
		<link rel="stylesheet" href="/css/template.css" type="text/css" media="screen" title="no title" charset="utf-8" />
		<script src="/jquery/jquery.min.js" type="text/javascript"></script>
		<script src="/jquery/jquery.validationEngine-en.js" type="text/javascript"></script>
		<script src="/jquery/jquery.validationEngine.js" type="text/javascript"></script>

		<!-- AJAX SUCCESS TEST FONCTION	
			<script>function callSuccessFunction(){alert("success executed")}
					function callFailFunction(){alert("fail executed")}
			</script>
		-->
		
		<script>	
		$(document).ready(function() {

			
			$("#formID").validationEngine()
		
			
			//$.validationEngine.loadValidation("#date")
			//alert($("#formID").validationEngine({returnIsValid:true}))
			//$.validationEngine.buildPrompt("#date","This is an example","error")	 		 // Exterior prompt build example
			//$.validationEngine.closePrompt(".formError",true) 							// CLOSE ALL OPEN PROMPTS
		});
		
		// JUST AN EXAMPLE OF CUSTOM VALIDATI0N FUNCTIONS : funcCall[validate2fields]
		function validate2fields(){
			if($("#firstname").val() =="" ||  $("#lastname").val() == ""){
				return false;
			}else{
				return true;
			}
		}
	</script>	
<title>Document sans titre</title>
</head>
<body>
    <form  class="formular" method="post" action="#" id="formID" enctype="multipart/form-data">
        <fieldset>
            <legend>Déposer une annonce</legend>
            <fieldset>
                <legend>User Region</legend>
                <span>Région:</span>
                <label><?php 
                
                $requete = $sql->query("SELECT nom_region FROM region where id_region="."'".$table['region']."'");    
                $resultat = $sql->fetch_array($requete);
                echo $resultat['nom_region'];?></label>
            </fieldset>
            <fieldset>
                <legend>Categorie Annonce</legend>
                <span>Categorie:</span>
                <label><?php 
                $requete = $sql->query("SELECT nom_categorie FROM categorie where id_categorie="."'".$table['categorie']."'");    
                $resultat = $sql->fetch_array($requete);
                echo $resultat['nom_categorie'];?></label>
            </fieldset>
            <fieldset>
                <legend>Vous êtes</legend> 
                <span>Vous êtes &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;:&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<?php echo $table['vous_etes']; ?><br/></span>  
                <span>Votre nom &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;:&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><label><?php echo $table['nom'];?><br/></label>
                <span>Votre prenom &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;:&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><label> <?php echo $table['prenom'];?><br/></label>
                <span>Email&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;:&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><label><?php echo $table['mail']?><br/></label>
                <span>Telephone&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;:&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><label><?php echo $table['telephone']?><br/></label>
            </fieldset> 
            <fieldset>
                <legend>Annonce</legend>
                <label>Type d'annonce&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;:&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<?php echo $table['type_annonce'];?><br/></label>
                <span>Titre de l'annonce &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;:&nbsp;&nbsp;&nbsp;&nbsp;</span>
                <label>
                   <?php echo $table['titreannonce']?><br/>
                </label>
                <span>Texte  de l'annonce&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;:&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span>
                <label>
                    <?php echo $table['texteannonce']?><br/>
                </label>
                <span>Prix &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;:&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span>
                <label> 
                    <?php echo $table['prix']?> Ouguiya<br/>
                </label>
                <span> <input name="ok" class="submit" type="submit" value="confirmation!"/></span>
                 
            </fieldset>
            <tr>
                          <td align="center" class="txt_4g"><a href="./formulaire_ajoutAnnonce.php?param=<?php echo $_GET['param']?>">modifier vos informations </a></td></td>
                        </tr>
        </fieldset>
    </form>
</body>
</html>

<?php //include_once"../commune/pied.php";?>
